<!DOCTYPE html>
<html>
    {% load static %}
<!-- import CSS -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
<!-- import Vue before Element -->
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

<!-- Bootstrap core CSS -->
<link href="{% static 'assets/css/bootstrap.css' %}" rel="stylesheet">
<!--external css-->
<link href="{% static 'assets/font-awesome/css/font-awesome.css' %}" rel="stylesheet" />
    
<!-- Custom styles for this template -->
<link href="{% static 'assets/css/style.css' %}" rel="stylesheet">
<link href="{% static 'assets/css/style-responsive.css' %}" rel="stylesheet">

<!-- js placed at the end of the document so the pages load faster -->
<script src="{% static 'assets/js/jquery.js' %}"></script>
<script src="{% static 'assets/js/bootstrap.min.js' %}"></script>
<script class="include" type="text/javascript" src="{% static 'assets/js/jquery.dcjqaccordion.2.7.js' %}"></script>
<script src="{% static 'assets/js/jquery.scrollTo.min.js' %}"></script>
<script src="{% static 'assets/js/jquery.nicescroll.js' %}" type="text/javascript"></script>


<!--common script for all pages-->
<script src="{% static 'assets/js/common-scripts.js' %}"></script>

<!--script for this page-->

<!-- 引入刚刚下载的 ECharts 文件 -->
<script src="{% static 'assets/js/echarts.js' %}"></script>
<script src="{% static 'assets/js/highlight.min.js' %}"></script>
    <script>
        hljs.highlightAll();
    </script>

    <script src="{% static 'assets/dist/notice.min.js' %}"></script>
    <script>
        const notice = new Notice();
    </script>

    <script src="{% static 'assets/js/main.js' %}"></script>
    <link rel="stylesheet" href="{% static 'assets/css/style.css' %}">
    <link rel="stylesheet" href="{% static 'assets/dist/notice.min.css' %}">
    <link rel="stylesheet" href="{% static 'assets/css/default.min.css' %}">

    <script>
        //plant改变
        $(document).ready(function() {
            $("#plant2").change(function(){ 
                
                $.ajax({
                    type: "POST",
                    url: "{% url 'MM:ajax_getStockByName' %}",
                    data:{
                        csrfmiddlewaretoken: '{{ csrf_token }}',
                        //plant值
                        name:$("#plant2").val(),
                    },
                    
                    success: function(data) {
                        $('#test2').text(data);
                        //add：如果没有该工厂，回传回来一个message提示
                        var dataObj = eval("("+data+")");
                        //注意：plant选择空的时候，这三项也返回空
                        fields = dataObj[0].fields
                        $("#pgrp2").val(fields.pGrp);
                        $("#pOrg2").val(fields.pOrg);
                        $("#company2").val(fields.companyCode);
                    },
                    failure: function() {
    
                    }
                });
            
            }); 
            $("#plant3").change(function(){ 
                
                $.ajax({
                    type: "POST",
                    url: "{% url 'MM:ajax_getStockByName' %}",
                    data:{
                        csrfmiddlewaretoken: '{{ csrf_token }}',
                        //plant值
                        name:$("#plant3").val(),
                    },
                    
                    success: function(data) {
                        $('#test2').text(data);
                        //add：如果没有该工厂，回传回来一个message提示
                        var dataObj = eval("("+data+")");
                        //注意：plant选择空的时候，这三项也返回空
                        fields = dataObj[0].fields
                        $("#pgrp3").val(fields.pGrp);
                        $("#pOrg3").val(fields.pOrg);
                        $("#company3").val(fields.companyCode);
                    },
                    failure: function() {
    
                    }
                });
            
            }); 
            $.ajax({
                type: "POST",
                url: "{% url 'MM:ajax_load_sorg' %}",
                data:{
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                },
                success: function(data) {
                    var dataObj = eval("("+data+")");
                    var out = "<option value='' >请选择销售组织</option>";
                    var i;
                    for(i = 0; i < dataObj.length; i++) {
                        out += '<option value=' + dataObj[i].Sorg+'>'+ dataObj[i].Sorg + '--' + dataObj[i].Name1 + '</option>' ;
                    }
                    var items=document.getElementsByName("sorg");
                    for(i = 0; i < items.length; i++) {
                        items[i].innerHTML=out;
                    } 
                },
                failure: function() {
    
                }
            });
            $.ajax({
                type: "post",
                url: "{% url 'MM:ajax_load_meaunit' %}",
                data:{
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                },
                success: function(data) {
                    var dataObj = eval("("+data+")");
                    var out = "<option value='' >请选择单位</option>";
                    var i;
                    for(i = 0; i < dataObj.length; i++) {
                        out += '<option value=' + dataObj[i].Meaunit+'>'+ dataObj[i].Meaunit + '--' + dataObj[i].Name + '</option>' ;
                    }
                    
                    var items=document.getElementsByName("meaunit");
                    console.log(items);
                    for(i = 0; i < items.length; i++) {
                        items[i].innerHTML=out;
                    }
                },
                failure: function() {
    
                }
            });
            
            $.ajax({
                type: "post",
                url: "{% url 'MM:ajax_load_plant' %}",
                data:{
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                },
                success: function(data) {
                    var dataObj = eval("("+data+")");
                    var out = "<option value='' >请选择工厂</option>";
                    var i;
                    for(i = 0; i < dataObj.length; i++) {
                        out += '<option value=' + dataObj[i].Plant+'>'+ dataObj[i].Plant + '--' + dataObj[i].Name + '</option>' ;
                    }
                    //由于一个页面里有多个表单，所以用name寻找各个下拉框进行赋值
                    var items=document.getElementsByName("plant");
                    console.log(items);
                    for(i = 0; i < items.length; i++) {
                        items[i].innerHTML=out;
                    }
                },
                failure: function() {
    
                }
            });
            $.ajax({
                type: "post",
                url: "{% url 'MM:ajax_load_porg' %}",
                data:{
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                },
                success: function(data) {
                    var dataObj = eval("("+data+")");
                    var out = "<option value='' >请选择采购组织</option>";
                    var i;
                    for(i = 0; i < dataObj.length; i++) {
                        out += '<option value=' + dataObj[i].Porg+'>'+ dataObj[i].Porg + '--' + dataObj[i].Name + '</option>' ;
                    }
                    var items=document.getElementsByName("porg");
                    for(i = 0; i < items.length; i++) {
                        items[i].innerHTML=out;
                    } 
                },
                failure: function() {
    
                }
            });
            $.ajax({
                type: "post",
                url: "{% url 'MM:ajax_load_company' %}",
                data:{
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                },
                success: function(data) {
                    var dataObj = eval("("+data+")");
                    var out = "<option value='' >请选择公司编码</option>";
                    var i;
                    for(i = 0; i < dataObj.length; i++) {
                        out += '<option value=' + dataObj[i].CompanyCode+'>'+ dataObj[i].CompanyCode + '--' + dataObj[i].Name + '</option>' ;
                    }
                    var items=document.getElementsByName("company");
                    for(i = 0; i < items.length; i++) {
                        items[i].innerHTML=out;
                    } 
                },
                failure: function() {
    
                }
            });
            $.ajax({
                type: "post",
                url: "{% url 'MM:ajax_load_pgrp' %}",
                data:{
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                },
                success: function(data) {
                    var dataObj = eval("("+data+")");
                    var out = "<option value='' >请选择采购组</option>";
                    var i;
                    for(i = 0; i < dataObj.length; i++) {
                        out += '<option value=' + dataObj[i].Pgrp+'>'+ dataObj[i].Pgrp + '--' + dataObj[i].Name + '</option>' ;
                    }
                    var items=document.getElementsByName("pgrp");
                    for(i = 0; i < items.length; i++) {
                        items[i].innerHTML=out;
                    }  
                },
                failure: function() {
    
                }
            });
            
        });
    function re(){
        document.getElementById("fu").style.display="none";
                document.getElementById("yuan").style.display="";
    }
    </script>
    <body>
        <section id="main-content">
            <section class="wrapper">
                <h3><i class="fa fa-angle-right"></i> 查看商品库存
                </h3>
                
                <div class="row mt">
                  <div class="col-lg-12">
                  <div class="form-panel3">
                        
                      <form id='material1' class="form-horizontal style-form" method="get">
                          <!-- <div class="form-group"> -->
                              <!-- <label class="col-sm-2 col-sm-2 control-label">搜索</label> -->
                              <div class="col-sm-3">
                                  <input class="form-control" id="materialInput1" name='pk' type="text"  placeholder="请输入商品编号" required>
                              </div>
                              <div class="col-sm-3">
                                <select class="form-control" id="materialInput2" name='plant' required></select>
                            </div>
                            <div class="col-sm-3">
                                <select class="form-control" id="materialInput3" name="sloc" required>
                                    <option value=''>请选择存储位置</option> 
                                    <option value='TG00'>TG00--贸易商品</option>
                                    <option value='RM00'>RM00--原材料</option>
                                    <option value='SF00'>SF00--半成品</option>
                                    <option value='FG00'>FG00--产成品</option>
                                    <option value='MI00'>MI00--混合产品</option>
                                    <option value='RE00'>RE00--退货产品</option> 
                                     
                                </select>
                            </div>
                              <button type="submit" formmethod="post" class="btn btn-success "><i class="fa fa-search"></i></button>
                            </form>
                              
                              <div class="col-sm-12">
                              <button type="button" class="btn btn-link " data-toggle="modal" data-target="#myModal1">忘记编号？</button><br>
                                     
                                      </div>
                                    </div>
                                </div>
                                </div>
                                
                      
                                      <div class="row mt">
                                        <div class="col-md-12">
                                          <div class="col-md-12">
                                           
                                                <div class="pull-right">
                                                    <button type="button" class="btn btn-theme03" data-toggle="modal" data-target="#myModal2">历史库存</button>
                                                  </div><br><br>
                                          <div class="content-panel">
                                              <!-- <div class="form-panel2"> -->
                                              
                                              <table class="table table-striped table-advance table-hover">
                                                      <h4><i class="fa fa-angle-right"></i> 商品库存列表</h4>
                                                      <hr>
                                                  <thead>
                                                  <tr>
                                                      <th><i class="fa fa-bullhorn"></i> 库存类型</th>
                                                      <th><i class="fa fa-question-circle"></i> 当前库存数量</th>
                                                      
                                                  </tr>
                                                  </thead>
                                                  <tbody >
                                                    <tr>
                                                        <td>在途库存</td>
                                                        <td id="stock0"></td>
                                                    </tr>
                                                    <tr>
                                                        <td>无限制库存</td>
                                                        <td id="stock1"></td>
                                                    </tr>
                                                    <tr>
                                                        <td>冻结库存</td>
                                                        <td id="stock2"></td>
                                                    </tr>
                                                    <tr>
                                                        <td>质量检验库存</td>
                                                        <td id="stock3"></td>
                                                    </tr>
                                                </tbody>
                                              </table>
                                          </div>
                                          </div>
                                           
                                            </div>
                                        </div><!-- /col-md-12 -->
                                    </div><!-- /row -->
                      
              
          </section>
        </section><!-- /MAIN CONTENT -->
        <div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
            <div class="modal-dialog">
              <div class="modal-content">
                <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                  <h4 class="modal-title" id="myModalLabel">搜索商品编号</h4>
                </div>
                <div class="modal-body">
                  <!-- Hi there, I am a Modal Example for Dashgum Admin Panel. -->
                  <!-- 搜索条件 -->
                  <form  id="material2" class="form-horizontal style-form">
                    <div class="form-group">
                        <label class="col-sm-4 col-sm-4 control-label">
                          <div class="pull-right">商品名称： </div>
                        </label>
                        <div class="col-sm-5">
                            <input class="form-control" type="text" name="mname" id="mname" >
                        </div>
                    </div>
    
    
                    <div class="form-group">
                        <label class="col-sm-4 col-sm-4 control-label">
                          <div class="pull-right">商品类型：</div>
                        </label>
                        <div class="col-sm-5">
                            <select name="mType" id="mType" class="form-control" >
                                <!-- 默认为未选 -->
                                <option value=''>请选择商品类型</option>
                                <option value='RM'>RM--原材料</option>
                                <option value='HALB'>HALB--半成品</option>
                                <option value='FERT'>SF00--成品</option>
                                <option value='FREMD'>FG00--外部采购物料</option>
                                <option value='PROC'>MI00--加工物料</option>
                                <option value='HAWA'>RE00--贸易货物</option> 
                                <option value='HIBE'>RE00--经营供应</option>
                            </select>
                           
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 col-sm-4 control-label">
                          <div class="pull-right">工业部门：</div>
                        </label>
                        <div class="col-sm-5">
                            <select class="form-control" name='industrySector' id='industrySector' >
                                <option value=''>请选择工业部门</option>
                                <option value='C'>化学工业</option>
                                <option value='M'>机械工业</option>
                                <option value='W'>药剂工业</option>
                                <option value='F'>设备工程</option>
                                <option value='R'>零售</option>
                            </select>
                            
                        </div>
                    </div>
                    
    
                    <div class="form-group">
                        <label class="col-sm-4 col-sm-4 control-label">
                          <div class="pull-right">工厂：</div>
                        </label>
                        <div class="col-sm-5">
                            <select class="form-control" name='plant' id='plant' ></select>
                            
                        </div>
                    </div>
                    
    
                    <div class="form-group">
                        <label class="col-sm-4 col-sm-4 control-label">
                          <div class="pull-right">存储位置：</div>
                        </label>
                        <div class="col-sm-5">
                            <select class="form-control" name="sloc" id="sloc" >
                                <option value=''>请选择存储位置</option>
                                <option value='TG00'>TG00--贸易商品</option>
                                <option value='RM00'>RM00--原材料</option>
                                <option value='SF00'>SF00--半成品</option>
                                <option value='FG00'>FG00--产成品</option>
                                <option value='MI00'>MI00--混合产品</option>
                                <option value='RE00'>RE00--退货产品</option> 
                            </select>
                            
                        </div>
                    </div>
                    <div class="form-group">
                        <!-- <label class="col-sm-1 col-sm-1 control-label"></label> -->
                        <label class="col-sm-4 col-sm-4 control-label">
                            <div class="pull-right">创建者编号：</div>
                            </label>
                        <div class="col-sm-5">
                            <input name="uid" id="uid" type="text" class="form-control">
                        </div>
                        <div class="col-sm-2">
                            <input type="submit"  class="btn btn-theme02">
                            </div>
                    </div>
                    
    
                </form>
                {% comment %} <h4> 供应商</h4> {% endcomment %}
                {% comment %} <hr> {% endcomment %}
                <table  class="table table-bordered table-striped table-condensed">
                  *双击填入编号                                       
                  <thead>
                  <!-- 搜索编号返回的属性 style="width: 100px;"-->
                  <tr>
                      <th> 商品编号</th>
                      <th> 商品名称</th>
                      <th> 商品类型</th>
                      <th> 工业部门</th>
                      <th> 工厂</th>
                      <th> 存储位置</th>
                      <th> 创建者编号</th>
                  </tr>
                  </thead>
                  <tbody id="searchDiv"></tbody>
              </table>
                
    
                </div>
                
                <div class="modal-footer">
                  
                </div>
              </div>
            </div>
          </div>

          <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2" aria-hidden="true">
            <div class="modal-dialog">
              <div class="modal-content">
                <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                  <h4 class="modal-title" id="myModalLabel">查看历史库存</h4>
                </div>
                <div class="modal-body">
                   <div id="main" style="width: 600px;height:400px;"></div>
                </div>
                
                <div class="modal-footer">
                  
                </div>
              </div>
            </div>
          </div>
        <!--main content end-->
        <!--footer start-->
        <footer class="site-footer">
            <div class="text-center">
                2014 - Alvarez.is
                <a href="basic_table.html#" class="go-top">
                    <i class="fa fa-angle-up"></i>
                </a>
            </div>
        </footer>
        <!--footer end-->
    </section>

        {% comment %} <textarea id="item_result"></textarea> {% endcomment %}

        <script>
            //商品搜索 三项内容都填才能发起搜索，否则返回提示:请填写xxx（第一个未填的项）；如果搜不到，返回提示：没有符合条件的商品（这个也不返回了，可以判断是否为序列中只有一个元素）
            $('#material1').on('submit', function(e) {
                e.preventDefault();
                $.ajax(
                {
                    type: "POST",
                    url: "{% url 'MM:ajax_search_stock_history' %}",
                    data:{
                        dataType: "json",
                        csrfmiddlewaretoken: '{{ csrf_token }}',
                        //输入三个搜索框的值
                        material_id: $("#materialInput1").val(),
                        plant: $("#materialInput2").val(),
                        sloc: $("#materialInput3").val(),
                    },
                    success: function(data) {
                        //data={"status": 1, "message": [[2022, 8, 0, 0, 0, 0], [2022, 7, 100, 0, 0], [2022, 6, -75, 0, 0], [2022, 5, -125, 0, 0], [2022, 4, -375, 0, 0], [2022, 3, 625, 0, 0], [2022, 2, 625, 300, 200]]}
                        var dataObj = eval("("+data+")");
                        $('#item_result').text(data);
                        //var dataObj =([[2022,5,23,54,43,21],[2022,4,74,-56,3],[2022,3,46,12,90],[2022,2,74,-56,3],[2022,1,46,12,90],[2021,12,74,-56,3]]) ;
                        document.getElementById("stock0").innerHTML=dataObj.message[0][2];
                        document.getElementById("stock1").innerHTML=dataObj.message[0][3];
                        document.getElementById("stock2").innerHTML=dataObj.message[0][4];
                        document.getElementById("stock3").innerHTML=dataObj.message[0][5];
                  
                        // 基于准备好的dom，初始化echarts实例
                        var myChart = echarts.init(document.getElementById('main'));
                  
                        // 指定图表的配置项和数据
                        var option = {
                        xAxis: {
                          type: 'category',
                          data: [ dataObj.message[5][0]+'.'+dataObj.message[5][1],dataObj.message[4][0]+'.'+dataObj.message[4][1],dataObj.message[3][0]+'.'+dataObj.message[3][1],dataObj.message[2][0]+'.'+dataObj.message[2][1],dataObj.message[1][0]+'.'+dataObj.message[1][1], dataObj.message[0][0]+'.'+dataObj.message[0][1]]
                        },
                        yAxis: {
                          type: 'value'
                        },
                        legend: {
                          data: ['无限制库存', '冻结库存',"质量检验库存"], //图例的数据数组
                        },
                        series: [
                        {
                          itemStyle : { normal: {label : {show: true}}},
                          name: "无限制库存",
                          data: [dataObj.message[5][2],dataObj.message[4][2], dataObj.message[3][2], dataObj.message[2][2], dataObj.message[1][2], dataObj.message[0][3]],
                          type: 'line'
                        },
                        {
                          itemStyle : { normal: {label : {show: true}}},
                          name: "冻结库存",
                          data: [dataObj.message[5][3],dataObj.message[4][3], dataObj.message[3][3],dataObj.message[2][3], dataObj.message[1][3],dataObj.message[0][4]],
                          type: 'line'
                        },
                        {
                          itemStyle : { normal: {label : {show: true}}},
                          name: "质量检验库存",
                          data: [dataObj.message[5][4],dataObj.message[4][4], dataObj.message[3][4],dataObj.message[2][4], dataObj.message[1][4], dataObj.message[0][5]],
                          type: 'line'
                        }
                        ]
                    };
                  
                        // 使用刚指定的配置项和数据显示图表。
                        myChart.setOption(option);
                        
                    },
                    failure: function() {

                    }
                })
            });

            //编号搜索 如果搜不到，返回提示：没有符合条件的商品（这个就不返回了，可以判断是否为空）
            $('#material2').on('submit', function(e) {
                e.preventDefault();
                $.ajax(
                {
                    type: "POST",
                    url: "{% url 'MM:ajax_search_item' %}",
                    data:{
                        dataType: "json",
                        csrfmiddlewaretoken: '{{ csrf_token }}',
                        mid: '',
                        mname: $("#mname").val(),
                        mType: $("#mType").val(),
                        industrySector: $("#industrySector").val(),
                        sloc: $("#sloc").val(),
                        plant: $("#plant").val(),
                        uid: $('#uid').val(),
                    },
                    success: function(data) {

                        $('#item_result').text(data);
                    
                        var dataObj = eval("("+data+")");
                        var out = "";
                        var i;
                        
                        for(i = 0; i < dataObj.length; i++) {
                            //dataObj[i].fields.xx
                            fields = dataObj[i].fields
                            material = dataObj[i].material
                            stock = dataObj[i].stock
                            user = dataObj[i].user
                            out += '<tr><td>'+ material.id+ '</td><td>' + material.mname+ '</td><td>' + material.mType+ '</td><td>' + material.industrySector+ '</td><td>'+ stock.name+ '</td><td>'+ fields.sloc+ '</td><td>'+ user.username + '</td><tr>';
                        }
                        document.getElementById("searchDiv").innerHTML=out;
                    },
                    failure: function() {

                    }
                })
            });

            //双击行 信息进入“搜索商品条件”三个框
            $("table").on("dblclick","tr",function(e){
                document.getElementById("materialInput1").value=$(this).find('td').eq(0).text();
                document.getElementById("materialInput2").value=$(this).find('td').eq(4).text();
                document.getElementById("materialInput3").value=$(this).find('td').eq(5).text();
                $('#myModal1').modal('hide');
            });

        </script>


        <!-- 确认提示 -->
        <script>
            function tip(){
                if(confirm("您确认修改吗？")){
                return true;
                }
                else{
                return false;
                }
            } 
        </script>

        <script>
            //商品搜索 三项内容都填才能发起搜索，否则返回提示:请填写xxx（第一个未填的项）；如果搜不到，返回提示：没有符合条件的商品（这个也不返回了，可以判断是否为序列中只有一个元素）
            $('#material1').on('submit', function(e) {
                e.preventDefault();
                $.ajax(
                {
                    type: "POST",
                    url: "{% url 'MM:ajax_search_item' %}",
                    data:{
                        dataType: "json",
                        csrfmiddlewaretoken: '{{ csrf_token }}',
                        //输入三个搜索框的值
                        mid: $("#materialInput1").val(),
                        plant: $("#materialInput2").val(),
                        sloc: $("#materialInput3").val(),
                    },
                    success: function(data) {
                        document.getElementById("fu").style.display="";
                        $('#item_result').text(data);
                        var dataObj = eval("("+data+")");
                        fields = dataObj[0].fields;
                        material = dataObj[0].material;
                        stock = dataObj[0].stock;
                        user = dataObj[0].user;
                        //输入表单material3的属性的id
                        $("#pk2").val(material.id);
                        $("#mname2").val(material.mname); 
                        $("#mType2").val(material.mType);
                        $("#meaunit2").val(material.meaunit);
                        $("#netWeight2").val(material.netWeight);
                        $("#weightUnit2").val(material.weightUnit);
                        $("#transGrp2").val(material.transGrp);
                        $("#loadingGrp2").val(material.loadingGrp);
                        $("#industrySector2").val(material.industrySector);
                        $("#mGroup2").val(material.mGroup);
                        $("#sloc2").val(fields.sloc);
                        $("#sorg2").val(fields.sOrg);
                        $("#distrchannel2").val(fields.distrChannel);
                        $("#company2").val(stock.companyCode);
                        $("#porg2").val(stock.pOrg);
                        $("#pgrp2").val(stock.pGrp);
                        $("#plant2").val(stock.name);
                        //document.getElementById("material3").style.visibility="visible";
                    },
                    failure: function() {

                    }
                })
            });

            //编号搜索 如果搜不到，返回提示：没有符合条件的商品（这个就不返回了，可以判断是否为空）
            $('#material2').on('submit', function(e) {
                e.preventDefault();
                $.ajax(
                {
                    type: "POST",
                    url: "{% url 'MM:ajax_search_item' %}",
                    data:{
                        dataType: "json",
                        csrfmiddlewaretoken: '{{ csrf_token }}',
                        mid: '',
                        mname: $("#mname").val(),
                        mType: $("#mType").val(),
                        industrySector: $("#industrySector").val(),
                        sloc: $("#sloc").val(),
                        plant: $("#plant").val(),
                        uid: $('#uid').val(),
                    },
                    success: function(data) {

                        $('#item_result').text(data);
                    
                        var dataObj = eval("("+data+")");
                        var out = "";
                        var i;
                        
                        for(i = 0; i < dataObj.length; i++) {
                            //dataObj[i].fields.xx
                            fields = dataObj[i].fields
                            material = dataObj[i].material
                            stock = dataObj[i].stock
                            user = dataObj[i].user
                            out += '<tr><td>'+ material.id+ '</td><td>' + material.mname+ '</td><td>' + material.mType+ '</td><td>' + material.industrySector+ '</td><td>'+ stock.name+ '</td><td>'+ fields.sloc+ '</td><td>'+ user.username + '</td><tr>';
                        }
                        document.getElementById("searchDiv").innerHTML=out;
                    },
                    failure: function() {

                    }
                })
            });

            //双击行 信息进入“搜索商品条件”三个框
            $("table").on("dblclick","tr",function(e){
                document.getElementById("materialInput1").value=$(this).find('td').eq(0).text();
                document.getElementById("materialInput2").value=$(this).find('td').eq(4).text();
                document.getElementById("materialInput3").value=$(this).find('td').eq(5).text();
                $('#myModal1').modal('hide');
            });

            
        </script>

    </body>
</html>